<?php
require('functions/page_load.php');
require("fckeditor/fckeditor.php");

$settings_nav = true;

if($_SERVER['REQUEST_METHOD'] == 'POST'){

	$sql = "INSERT INTO trades SET 
			trade = '".mysql_real_escape_string($_POST['trade'])."',
			url = '".mysql_real_escape_string($_POST['url'])."',
			lead_cost = '".mysql_real_escape_string($_POST['lead_cost'])."',
			trade_content = '".mysql_real_escape_string(stripslashes($_POST['trade_content']))."'";
	$query = mysql_query( $sql ) or die ("Error in query: $sql. " . mysql_error());
	$new_id = mysql_insert_id();
	
	header("Location: edit_trade.php?new=true&id=".$new_id);

}

require('includes/header.php');
?>

<div class="side_container">
<h2 class="container_header">Navigation</h2>

<ul>
<li><a href="banners.php">Banners</a></li>
<li><a href="trades.php">Trades</a></li>
<li><a href="directory_categories.php">Directory Categories</a></li>
<li><a href="subscriptions.php">Subscriptions</a></li>
<li><a href="sms_packages.php">SMS Packages</a></li>
</ul>

</div>

<div class="main_container_wrapper">

	<div class="main_container">
	<h2 class="container_header">Add Trade</h2>
	
	<div id="top_links">
	<a href="trades.php" style="background-image: url(images/back.png); padding-left: 20px;">Back to Trades</a>
	</div>
	
	<?php echo $results; ?>
	
			<form method="post" action="">
			
			<!-- user details -->
			
			<div class="form_row_wrapper">
			<div class="form_row_left"><label for="name">Trade*:</label></div>
			<div class="form_row_right"><input type="text" name="trade" id="name" value="<?php echo $rs['trade']; ?>" onkeyup="buildUrl();" onkeydown="buildUrl();" /></div>
			</div>

			<div class="form_row_wrapper">
			<div class="form_row_left"><label for="url">Trade URL*:</label></div>
			<div class="form_row_right"><input type="text" name="url" id="url" value="<?php echo $rs['url']; ?>" /> <span>This must be a unique and web-safe name for the trade.</span></div>
			</div>

			<div class="form_row_wrapper">
			<div class="form_row_left"><label for="lead_cost">Lead cost:</label></div>
			<div class="form_row_right"><input type="text" name="lead_cost" id="lead_cost" value="<?php echo $rs['lead_cost']; ?>" /></div>
			</div>
			
			<div class="form_row_wrapper">
			<div class="form_row_left"><label>Content:</label></div>
			<div class="form_row_right">
			<?php
			$oFCKeditor = new FCKeditor('trade_content');
			$oFCKeditor->Height = '400';
			$oFCKeditor->BasePath = '/admin/fckeditor/';
			$oFCKeditor->Value = $rs['trade_content'];
			$oFCKeditor->Create();
			?>
			</div>
			</div>
			
			<div class="form_row_wrapper">
			<div class="form_row_left">&nbsp;</div>
			<div class="form_row_right"><input type="image" src="images/save_button.png" alt="Save" /></div>
			</div>
			
			</form>
		
	</div>

</div>
	
<?php
	require('includes/footer.php');
?>